package com.enjoy.udp.unicast;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;

/**
 * Created by HP on 2019/7/15.
 */
public class UdpAnswerSide {
    public final static String ANSWER = "古诗来了：";

    public void run(int port) throws Exception {
        EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap b = new Bootstrap();
            b.group(group).channel(NioDatagramChannel.class)
                    .handler(new AnswerHandler());
            ChannelFuture f=b.bind(port).sync();
            System.out.println("应答服务已经启动......");
            f.channel().closeFuture().sync();
        } finally {
              group.shutdownGracefully().sync();
        }

    }

    public static void main(String[] args) throws Exception {
        int port=8080;
        new UdpAnswerSide().run(port);
    }
}
